package com.ming.yygh.common.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class knife4jConfig {

    // http://localhost:8201/doc.html#/
    @Bean(value = "adminApiConfig")
    public Docket adminApiConfig() {
        Docket docket = new Docket(DocumentationType.OAS_30)
                .apiInfo(new ApiInfoBuilder()
                        .title("Hospital RESTful APIs")
                        .description("# Hospital RESTful APIs")
                        .termsOfServiceUrl("http://www.xx.com/")
                        .contact(new Contact("light", "", ""))
                        .version("1.0")
                        .build())
                //分组名称
                .groupName("adminAPI")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.ming.yygh"))
                .paths(PathSelectors.regex("/admin/.*"))
                .build();
        return docket;
    }

    @Bean(value = "webApiConfig")
    public Docket webApiConfig() {
        Docket docket = new Docket(DocumentationType.OAS_30)
                .apiInfo(new ApiInfoBuilder()
                        .title("Hospital RESTful APIs")
                        .description("# Hospital RESTful APIs")
                        .termsOfServiceUrl("http://www.xx.com/")
                        .contact(new Contact("light", "", ""))
                        .version("1.0")
                        .build())
                //分组名称
                .groupName("webAPI")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.ming.yygh"))
                .paths(PathSelectors.regex("/api/.*"))
                .build();
        return docket;
    }
}
